package cn.gdpu.course.web.controller.student;

import cn.gdpu.course.constant.Constant;
import cn.gdpu.course.dao.CourseDao;
import cn.gdpu.course.dao.CourseStudentDao;
import cn.gdpu.course.dao.SettingDao;
import cn.gdpu.course.dao.StudentDao;
import cn.gdpu.course.dao.domain.CourseStudent;
import cn.gdpu.course.dao.domain.Student;
import cn.gdpu.course.web.bean.PageBean;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/4/5.
 */

@Controller
@RequestMapping("/student/score")
public class StuScoreController {

	@Resource
	private CourseStudentDao courseStudentDao;

	@Resource
	private StudentDao studentDao;

//	@Resource
//	private CourseDao courseDao;
//
//	@Resource
//	private SettingDao settingDao;

	@RequestMapping(method = {RequestMethod.GET, RequestMethod.POST})
	public String index(HttpServletRequest request, ModelMap model) {
		String username = (String) request.getSession().getAttribute(Constant.user_name);
		Student student = new Student();
		student.setSname(username);
		student = studentDao.findBySname(student);
		model.addAttribute("username", username);
		model.addAttribute("studentno", student.getSno());
		return "student/score";
	}

	@ResponseBody
	@RequestMapping(value = "/list", method = {RequestMethod.GET, RequestMethod.POST})
	public PageBean<CourseStudent> list(ModelMap model, CourseStudent courseStudent) {
		PageBean<CourseStudent> data = new PageBean<CourseStudent>();

		if (null == courseStudent.getSno() || "".equals(courseStudent.getSno())){
			data.setData(new ArrayList<CourseStudent>());
			return data;
		}
		List<CourseStudent> courseStudents = courseStudentDao.findscore(courseStudent);
		data.setData(courseStudents);
		return data;
	}

}
